<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>点标记添加点击事件</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta content="initial-scale=1.0, user-scalable=no" name="viewport">
    <meta content="IE=Edge" http-equiv="X-UA-Compatible">
    <style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=ErvyOA38YNoOZzrryZUwLmhYPujyidGy"></script>
</head>
<body>
<div id="container"></div>
<input id="longitude" th:value="${session.localtion.longitude}" type="hidden"/>
<input id="latitude" th:value="${session.localtion.latitude}" type="hidden"/>
<input id="name" th:value="${session.localtion.name}" type="hidden"/>
<input id="address" th:value="${session.localtion.address}" type="hidden"/>
<input id="tell" th:value="${session.localtion.tell}" type="hidden"/>
</body>
</html>
<script>
    let longitude = document.getElementById("longitude").value;
    let latitude = document.getElementById("latitude").value;
    let name = document.getElementById("name").value;
    let tell = document.getElementById("tell").value;
    let address = document.getElementById("address").value;

    var map = new BMapGL.Map('container');
    var point = new BMapGL.Point(longitude, latitude);
    map.centerAndZoom(point, 18);
    // 创建点标记
    var marker = new BMapGL.Marker(point);
    map.addOverlay(marker);
    // 创建信息窗口
    var opts = {
        width: 200,
        height: 100,
        title: name
    };
    var infoWindow = new BMapGL.InfoWindow('地址：' + address + "<br>" + "电话：" + tell, opts);
    // 点标记添加点击事件
    marker.addEventListener('click', function () {
        map.openInfoWindow(infoWindow, point); // 开启信息窗口
    });
</script>